<?php
class content{

	public function display(){
		$pid = isset($_GET["pid"]) ? $_GET["pid"] : 0;
		switch($pid){
			case 1:
				$this->displayHome();
				break;
			case 2:
				$this->displayShop();
				break;
			case 3:
				$this->displayPackli();
				break;
			case 4:	
				$this->displayKontakt();
				break;
			case 50:
				$this->displayEinkaufen();
				break;
			case 51:
				$this->displayVerpacken();
				break;
			case 52:
				$this->displayStats();
				break;
			case 53:
				$this->displayAdmin();
				break;
			case 90:
				$this->displayLogin();
				break;
			case 91:
				$this->displayRegister();
				break;
			case 100:
				$this->login();
				break;
			case 101:
				$this->logout();
				break;
			default:
				$this->displayHome();
		}
	}
	
	private function displayHome(){
	?>
	<div id="intro">
	<p>Wir wollen dir das Päckli kriegen vereinfachen!</p>
	</div>


	<div id="default-packages">
		<h1>Standart-Päckli</h1>
		 <ul class="ui-tabs-nav">  
        <li class="ui-tabs-nav-item ui-tabs-selected" id="nav-fragment-1"><a href="#fragment-1"><img src="" alt="" /><span>Homer</span></a></li>  
        <li class="ui-tabs-nav-item" id="nav-fragment-2"><a href="#fragment-2"><img src="" alt="" /><span>Andy Laken</span></a></li>  
        <li class="ui-tabs-nav-item" id="nav-fragment-3"><a href="#fragment-3"><img src="" alt="" /><span>Husain</span></a></li>  
        <li class="ui-tabs-nav-item" id="nav-fragment-4"><a href="#fragment-4"><img src="" alt="" /><span>Chaplin</span></a></li>  
    </ul>  
    <!-- First Content -->  
    <div id="fragment-1" class="ui-tabs-panel" style="">  
        <img src="img/default.jpg" alt="" />  
        <div class="info" >  
        <h2><a href="#" >Schokolaaaaade</a></h2>  
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla tincidunt condimentum lacus. Pellentesque ut diam....<a href="#" >read more</a></p>  
        </div>  
    </div>  
    <!-- Second Content -->  
    <div id="fragment-2" class="ui-tabs-panel ui-tabs-hide" style="">  
        <img src="img/default.jpg" alt="" />  
        <div class="info" >  
        <h2><a href="#" >kommschooon, ein Scherz ist erlaubt!</a></h2>  
        <p>Vestibulum leo quam, accumsan nec porttitor a, euismod ac tortor. Sed ipsum lorem, sagittis non egestas id, suscipit....<a href="#" >read more</a></p>  
        </div>  
    </div>  
    <!-- Third Content -->  
    <div id="fragment-3" class="ui-tabs-panel ui-tabs-hide" style="">  
        <img src="img/default.jpg" alt="" />  
        <div class="info" >  
        <h2><a href="#" >wie wärs mit extra sportlich?</a></h2>  
        <p>liquam erat volutpat. Proin id volutpat nisi. Nulla facilisi. Curabitur facilisis sollicitudin ornare....<a href="#" >read more</a></p>  
        </div>  
    </div>  
    <!-- Fourth Content -->  
    <div id="fragment-4" class="ui-tabs-panel ui-tabs-hide" style="">  
        <img src="img/default.jpg" alt="" />  
        <div class="info" >  
        <h2><a href="#" >hole dir das Spass-Päckli!</a></h2>  
        <p>Quisque sed orci ut lacus viverra interdum ornare sed est. Donec porta, erat eu pretium luctus, leo augue sodales....<a href="#" >read more</a></p>  
        </div>  
    </div> 
	</div>
	<div id="custom-package">
	<img src="img/default.jpg" width="200px" height="200px" />
	<p>hier kann man ein eigenes paket erstellen, wenn man möchte!</p>
	</div>
	<?php
	}
	
	private function displayShop(){
	?>
	<h1>shop</h1>
	<div id="shop-navi">
	
	shop-navi
	</div>
	<div id="shop-content">
	<!-- Keep all menus within masterdiv-->
<div id="masterdiv">
	muss nicht div sein, bild ging auch
	<div class="menutitle" onclick="SwitchMenu('sub1')">Schockoriegel</div>
	<span class="submenu" id="sub1">
		<table>
		<tr><td><img src="img/default.jpg" width="40px" height="40px" /></td><td><img src="img/default.jpg" width="40px" height="40px" /></td><td><img src="img/default.jpg" width="40px" height="40px" /></td></tr>
		<tr><td>Mars</td><td>Snickers</td><td>Bounty</td></tr>
		<tr><td>CHF. 2.-</td><td>CHF. 2.-</td><td>CHF. 2.-</td></tr>
		<tr><td>rein!</td><td>rein!</td><td>rein!</td></tr>
		</table>
	</span>
	<div class="menutitle" onclick="SwitchMenu('sub2')">Chips</div>
	<span class="submenu" id="sub2">

	</span>

	<div class="menutitle" onclick="SwitchMenu('sub3')">Drinks</div>
	<span class="submenu" id="sub3">
	</span>
	
	<div class="menutitle" onclick="SwitchMenu('sub4')">Süsses</div>
	<span class="submenu" id="sub4">

	</span>
</div>
	</div>
	<?php
	}
	
	private function displayPackli(){
		?>
		<h1>standart-päckli</h1>
		<?php
	}
	
	private function displayKontakt(){
		?>
		<h1>kontakt</h1>
		
		<form method="GET" action="<!--confimrpage-->">
		<label>Vorname</label><input type="text" required /></br>
		<label>Name</label><input type="text" required /></br>
		<label>E-Mail</label><input type="text" e-mail /></br>
		<input type="textarea" required rows="10" value="aöldskf" />
		<input type="submit" value="abschicken"/>
		</form>
		<?php
	}
	
	private function displayEinkaufen(){
		$dbconnect = NEW DB();
		$query = "SELECT user_id FROM user_table";
		$result = $dbconnect->fetch($query);
	
	}
	
	private function displayVerpacken(){
	}
	
	private function displayStats(){
	}
	
	private function displayAdmin(){
	}
	
	private function displayLogin(){
	?>
	<h1>login</h1>
	<form>
	</form>
	<?php
	}
	
	private function displayRegister(){
		?>
		<h1>registrieren</h1>
		<?php
	}
	
	private function login(){
	if ($_SERVER['REQUEST_METHOD'] == 'POST') {

      $username = $_POST['username'];
      $passwort = $_POST['passwort'];

      $hostname = $_SERVER['HTTP_HOST'];
      $path = dirname($_SERVER['PHP_SELF']);

      // Benutzername und Passwort werden überprüft
      if ($username == 'admin' && $passwort == 'Hallo123') {
       $_SESSION['angemeldet'] = true;

       // Weiterleitung zur geschützten Startseite
       if ($_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.1') {
        if (php_sapi_name() == 'cgi') {
         header('Status: 303 See Other');
         }
        else {
         header('HTTP/1.1 303 See Other');
         }
        }
//
// hier noch paar probleme
// header wird nicht geschickt, andere moeglichkeit?
//
//
       header('Location: http://'.$hostname.($path == '/' ? '?pid=50' : '?pid=50').'/index.php');
       exit;
       }
      }
	}
	
	private function logout(){
	session_start();
     session_destroy();

     $hostname = $_SERVER['HTTP_HOST'];
     $path = dirname($_SERVER['PHP_SELF']);

     header('Location: http://'.$hostname.($path == '/' ? '' : $path).'/index.php');
	}
}
